public class Demo3 {
    public static boolean isQuit = false;

    public static void main(String[] args) throws InterruptedException {
        //boolean isQuit = false;
        Thread t = new Thread(() -> {
            while(!isQuit){
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }

            System.out.println("t 线程执行结束");
        });

        t.start();
        Thread.sleep(2000);
        //修改 isQuit 变量，就能狗影响到 t 想爱你成结束了
        System.out.println("main 线程尝试终止 t 线程");
        isQuit = true;
    }
}
